home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9471 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Nedd help in getting file-type
  5. Date: 10 Mar 1996 10:38:22 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hv7iuINNq8s@keats.ugrad.cs.ubc.ca>
  8. References: <4hmooa$2i5@asterix.isd-pm.de>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4hmooa$2i5@asterix.isd-pm.de>,
  12. Guenter Saller <guenter@isd-pm.de> wrote:
  13. >Hi there,
  14. >
  15. >I got a problem how to get the file-type in a c-programm.
  16. >
  17. >Especially I had to recognice a EDCBIC-file.
  18. >
  19. >My question:
  20. >
  21. >    Is there any systemcall on SINIX 5.42 which returns the file-type?
  22.  
  23. Ask in comp.unix.programmer, this is not a C question.
  24.  
  25. Some file systems have meta-information about files which includes types. The
  26. metainformation stored in typical UNIX filesystems does not carry type (but
  27. does carry things like time/date stamps, permissions, ownership, etc).
  28.  
  29. There is a convention that the first two characters of a file form a magic
  30. number which identifies the type. For example, the characters #! indicate an
  31. interpreter file. Executables and object files have their own magic numbers.
  32.  
  33. The ``file'' utility program looks at the magic numbers (and other clues where
  34. magic numbers are lacking) to try to guess the file type. This program can be
  35. flexibly configured to recognize new file types via the /etc/magic
  36. configuration file.
  37.  
  38. If you want to recognize a particular file type, have a look at /etc/magic and
  39. the kinds of heuristics that implementations of ``file'' apply in trying to
  40. detect a particular file type.
  41.  
  42. Assuming that you only want to distinguish between EBCDIC and ASCII files, you
  43. can scan the first few characters and apply some sort of heuristic rule of
  44. thumb to guess which kind you are dealing with.  If you know something about
  45. the kind of information that these files are expected to contain, that can help
  46. you as well.
  47. -- 
  48.  
  49.